#include <iostream>
#include <sstream>
#include <vector>

int sumTime(std::vector<int> nums, int id)
{
    if (id >= nums.size() || nums[id] == -1)
        return 0;
    return nums[id] + std::max(sumTime(nums, 2 * id + 1), sumTime(nums, 2 * id + 2));
}

int main()
{
    std::string in_str;
    std::getline(std::cin, in_str);
    std::istringstream iss(in_str);

    int num;
    std::vector<int> num_vec;
    while (iss >> num)
    {
        num_vec.push_back(num);
    }

    int total_tm = sumTime(num_vec, 0);
    std::cout << total_tm << std::endl;

    return 0;
}